"""
Test that when a projection from a volume is registered to the
volume that it converges to the right solution (best case registration scenario)

"""
import pythonRegistration as pr
from numpy import array, ones
import itk, vtk
import ImageCompare

reload(pr)

reg=pr.registration()
reg.verbose = False

w2if = vtk.vtkWindowToImageFilter()
writer = vtk.vtkPNGWriter()

fixedFileName = 'C:/Lib/JointTrack/branches/bryan/Images/ushortim080-LAT.tif'
volFileName = 'C:/Lib/jointtrack/branches/TestData/vert1.vtk'
calFileName = 'C:/Lib/JointTrack/branches/bryan/Tests/good_cal.txt'
saveFileName = fixedFileName[:-4]+'_out.png'

reg.SetFixedImageFileName(fixedFileName)

print "Original ViewUp: ", reg.fixedImageCam.GetViewUp()
matrix = reg.fixedImageCam.GetViewTransformMatrix()
print "View Transform Matrix: ", matrix

##print "Modified ViewUp: ", reg.fixedImageCam.GetViewUp()

w2if.SetInput(reg.fixedImageRenderWindow)
w2if.Modified()
writer.SetInput(w2if.GetOutput())
writer.SetFileName(saveFileName)
writer.Write()

#return 0 if they match, 1 otherwise.
comp = ImageCompare.compare(saveFileName,fixedFileName)

junk=raw_input('Press Enter to continue')

#Test for positive match
try:
    assert(comp == 0)
    print "Test Success!"
except:
    print "Test Failure!"

